home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
AMIGA-CD 2
/
Amiga-CD - Volume 2.iso
/
gepackte_disketten
/
1993
/
10_93_2.dms
/
10_93_2.adf
/
SAS-Libraries
/
stack.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-09-27
|
1KB
|
65 lines
#include <exec/types.h>
#include <exec/memory.h>
#include <exec/semaphores.h>
#include <proto/exec.h>
struct StackEntry {
struct Node se_Node;
ULONG se_Value;
};
struct SignalSemaphore StackSema;
struct List StackList;
struct Library *SysBase;
int __saveds __asm
__UserLibInit (register __a6
struct Library *stacklib) {
SysBase = (*((void**)4));
NewList(&StackList);
InitSemaphore(&StackSema);
return(0);
}
void __saveds __asm
__UserLibCleanup (register __a6
struct Library *stacklib) {
struct StackEntry *se;
while(se = (struct StackEntry*)
RemHead(&StackList)) {
FreeMem((UBYTE*)se,
sizeof(struct StackEntry));
}
return;
}
ULONG __asm __saveds LIB_Pop(void) {
ULONG val = -1;
struct StackEntry *se;
ObtainSemaphore(&StackSema);
if(se = (struct StackEntry*)
RemHead(&StackList)) {
val = se->se_Value;
FreeMem((UBYTE*)se,
sizeof(struct StackEntry));
}
ReleaseSemaphore(&StackSema);
return(val);
}
ULONG __asm __saveds
LIB_Push(register __d0 ULONG val) {
struct StackEntry *se;
ObtainSemaphore(&StackSema);
if(se=(struct StackEntry*)AllocMem
(sizeof(struct StackEntry),
MEMF_PUBLIC|MEMF_CLEAR)) {
se->se_Value = val;
AddHead(&StackList,&se->se_Node);
}
else val = -1;
ReleaseSemaphore(&StackSema);
return(val);
}